/**
 *
 */
package cre.gutwo.convert;

import cre.gutwo.domain.DataModel;
import cre.gutwo.domain.DeviceInfo;
import cre.gutwo.util.Constants;
import cre.gutwo.util.FrameUtil;

import java.util.List;
import java.util.Map;

/**
 * @author Cre.Gu
 */
public class SwConverter extends DefaultConverter {

    @Override
    protected void putDestHeaders(DataModel re) {
        re.putAll(gainSwDestHeaders());
    }

    @Override
    protected void specConvert(DataModel dm, DataModel re) {
        // 需要清空的列
        // String[] specs = { Constants.COMPANY, Constants.PC_SITECODE };
        // 需要转换的列
        String[] specs2 = {Constants.LINKAGE_ID, Constants.PCID};

        // for (String spec : specs) {
        // clearValue(dm, spec, re);
        // }

        DeviceInfo di = gainDeviceInfo(dm);
        if (di != null) {
            for (String spec : specs2) {
                changeValDi(re, di, spec);
            }
        } else {
            // 记录deviceInfo为null
            re.setDeviceInfoFound(false);
        }

    }

    protected void clearValue(DataModel dm, String spec, DataModel re) {
        if (re.containsKey(spec)) {
            re.put(spec, "");
        }
    }

    @Override
    protected String gainDeviceName(DataModel dm) {
        return dm.get(Constants.PCName);
    }

    @Override
    public void findSames(List<DataModel> destDatas) throws Exception {
        for (Map.Entry<String, String> key : diNotFounds.entrySet()) {
            FrameUtil.println("device未匹配：" + key.getKey() + "，行号：" + key.getValue());
        }
    }
}
